/*
 * HandlerID.cpp
 *
 *  Created on: 31/05/2011
 *      Author: angeles
 */

#include "HandlerID.h"

void HandlerID::set_ruta_arch_ID(const string& ruta_arch_ID) {
	this->ruta_arch_ID = ruta_arch_ID;
}

void HandlerID::crear_arch_inicial() {
	fstream arch;

	arch.open(this->ruta_arch_ID.c_str(), fstream::app);
	if (arch.tellg() == 0) {
		arch.close();
		arch.open(this->ruta_arch_ID.c_str(), fstream::out);
		arch << "0";
	}
	arch.close();
}

int HandlerID::consultar_archivo() {
	ifstream arch;
	string s;
	stringstream ss;
	int ID;

	arch.open(this->ruta_arch_ID.c_str());
	getline(arch, s);
	arch.close();

	ss << s;
	ss >> ID;

	return ID;
}

void HandlerID::modificar_archivo() {
	fstream arch;

	int ID = this->consultar_archivo();
	++ ID;

	arch.open(this->ruta_arch_ID.c_str(), fstream::in | fstream::out);
	arch << ID << endl;
	arch.close();
}
